package com.itheima.test.code12;

import java.io.*;
import java.util.ArrayList;

/**
 * @author df
 * @date 2021/8/19
 */
public class CovertedDemo {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Student s1 = new Student("gege",22);
        Student s2 = new Student("gege",22);
        Student s3 = new Student("gege",22);
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("test-package\\a.txt"));
        ArrayList<Student> list = new ArrayList<>();
        list.add(s1);
        list.add(s2);
        list.add(s3);

        //我们往本地文件中写的是一个集合
        oos.writeObject(list);
        oos.close();

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test-package\\a.txt"));
        ArrayList<Student> list2 = (ArrayList<Student>) ois.readObject();
        for (Student student : list2) {
            System.out.println(student);
        }
        ois.close();

    }
}
